<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- 个人资料介绍 开始 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">个人资料</span>
        </h2>
        <span>
        <el-link type="primary" :href='"/member/"+this.memberId'>修改个人资料</el-link>
        </span>
      </header>
      <div class="t-infor-wrap">
        <!-- 讲师基本信息 -->
        <section class="fl t-infor-box c-desc-content">
          <div class="mt20 ml20">
            <section class="t-infor-pic">
              <img :src="loginInfo.avatar">
            </section>
            <h3 class="hLh30">
              <span class="fsize24 c-333">{{loginInfo.nickname}}</span>
            </h3>
            <div class="clear"></div>
          </div>
        </section>
        <div class="clear"></div>
      </div>
      <section class="mt30">
        <div>
          <header class="comm-title all-teacher-title c-course-content">
            <h2 class="fl tac">
              <span class="c-333">购买课程</span>
            </h2>
            <section class="c-tab-title">
              <a href="javascript: void(0)">&nbsp;</a>
            </section>
          </header>

          <!-- /无数据提示 开始-->
          <section v-if="courseInfoList.length==0" class="no-data-wrap">
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam">没有相关数据，小编正在努力整理中...</span>
          </section>
          <!-- /无数据提示 结束-->
          <article class="comm-course-list">
            <ul class="of">
              <li v-for="course in courseInfoList" :key="course.id">
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img :src="course.cover" class="img-responsive" >
                    <div class="cc-mask">
                      <a :href="'/course/'+course.id" title="开始学习" class="comm-btn c-btn-1">开始学习</a>
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a :href="'/course/'+course.id"  :title="course.title" class="course-title fsize18 c-333">{{course.title}}</a>
                  </h3>
                </div>
              </li>
            </ul>
            <div class="clear"></div>
          </article>
        </div>
      </section>
    </section>
    <!-- /讲师介绍 结束 -->
  </div>
</template>
<script>
import teacherApi from "@/api/teacher"
import cookie from 'js-cookie'
import courseApi from '@/api/course'
export default {
  asyncData({  error }) {
    //和文件名字一样
    return teacherApi.getTeacherById(1).then(response => {
      return { 
        teacher: response.data.data.teacher,
        courseList: response.data.data.courseList
      }
    })
  },
  data(){
  return{
    token:'',
    loginInfo: {
      id: '',
      age: '',
      avatar: '',
      mobile: '',
      nickname: '',
      sex: ''
    },
    memberId: '',
    courseInfoList: []
  }
},
created(){
    this.showInfo();
    this.getCourseList();
},
methods:{   
    showInfo() {
      var userStr = cookie.get("OE-user")

      if(userStr) {
        this.loginInfo = JSON.parse(userStr)
        this.memberId = this.loginInfo.id
      }
    },
    getCourseList() {
        courseApi.getBuyCourseInfo(this.loginInfo.id)
        .then(response=>{
           this.courseInfoList = response.data.data.buyCourse; 
        })
    }
}
}
</script>